﻿#ifndef DDSHEETLISTCTRL_H
#define DDSHEETLISTCTRL_H

#include "SheetGlobal.h"
#include "BaseInclude.h"

#include <QFrame>

struct SHEETLIST_COLUMNINFO
{
	QString strFieldName;
	QString strColoumnName;
	int     iColoumnWidth;
	int     iIsVisual;
};

class QListCtrlTableModel;
namespace Ui { class SheetListCtrl; }
class SHEET_EXPORT SheetListCtrl : public QWidget
{
	Q_OBJECT

public:
	SheetListCtrl(QWidget *parent = 0);
	~SheetListCtrl();

public:
	bool initialise(QString sql, int listid, int sheetBox, bool isCheck = false);
	void setTopWidget(bool isVisible);
	QList<int> getCheckedSheetID();
	int getNewID(QString tablename, QString colname);
	void initQueryCondition();

signals:
	void doubleClicked(int sheetID, int sheetBox, const QString & sheetName);
	void clicked(int sheetID, const QString & sheetName);

protected slots:
	void on_btnFirst_clicked();
	void on_btnUp_clicked();
	void on_btnDown_clicked();
	void on_btnLast_clicked();
	void on_btnJump_clicked();
	void on_btnQuery_clicked();
	void on_sheetListView_doubleClicked(const QModelIndex & index);
	void on_sheetListView_clicked(const QModelIndex & index);
	void on_strPageNum_editingFinished();
	void on_btnDelete_clicked();
	void on_btnUpdateName_clicked();
	void on_btnAudit_clicked();
	void discussSuccess(bool bSuccess);
	
private:
	void initUI();
	void initData();
	void initConnect();
	void initHeaderInfo();
	void initColumnInfo(int listid);
	void initSheetList(QString filterSql);
	void updatePageTurningBtn();
	bool modifySheetName(QString newSheetName, int sheetId);

private:
	Ui::SheetListCtrl * ui;
	
	int iListId;
	int iModuleType;
	int iCurPage;
	int iTotalPage;
	bool isShowCheck;
	int iSheetBox;//票箱

	QString strCurFilterSql;
	QListCtrlTableModel *pTableModel;
	QList<SHEETLIST_COLUMNINFO> listColoumnInfo;
};

class QListCtrlTableModel : public QRecordTableModel
{
	Q_OBJECT
public:
	QListCtrlTableModel(QObject * parent = NULL);
	~QListCtrlTableModel();

public:
	bool select(QString sql,bool isCheck = false);
	virtual Qt::ItemFlags flags(const QModelIndex &index) const;
	virtual QVariant data(const QModelIndex &index, int role) const;
	virtual bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole);
	bool getChecked(int i);
private:
	QList<bool> listCheck;
	bool isShowCheck;
};

#endif
